<template>
    <div>
        <div class="crumbs">
            问题描述：<Input type="text" v-model="info.title" ></Input>
            问题类别：<Select v-model="info.t">
                <Option :value="1">我是买家</Option>
                <Option :value="2">我是卖家</Option>
                <Option :value="3">其他问题</Option>
                <Option :value="4">隐藏类目</Option>
            </Select>
        </div>
        <div class="container">
            <quill-editor ref="myTextEditor" v-model="info.solution" :options="editorOption"></quill-editor>
            <el-button class="editor-btn" type="primary" @click="submit">提交</el-button>
        </div>
    </div>
</template>

<script>

    import 'quill/dist/quill.core.css';
    import 'quill/dist/quill.snow.css';
    import 'quill/dist/quill.bubble.css';
    import { quillEditor } from 'vue-quill-editor';
    import util from '../libs/util';

    export default {

        name: 'editor',

        created() {

        },

        data: function(){
            return {
                info: {
                    t: 0,
                    title: "",
                    solution: ""
                },
                editorOption: {
                    placeholder: 'Hello World'
                }
            }
        },

        components: {
            quillEditor
        },

        methods: {

            onEditorChange({ editor, html, text }) {
                this.content = html;
            },

            submit(){

                if(this.info.t==0 || this.info.title=="" || this.info.solution=="") {
                    this.$Message.info("请输入完整信息！");
                    return;
                }
                
                this.$http.post(util.baseURL+"help/addHelpInfo",this.info,
                    {emulateJSON: true})
                    .then(
                        (response)=>{
                            if(response.data.data) {
                                console.log(this.info);
                              this.$Message.info("添加成功");
                              this.$router.push({path:"/index/helplist"});
                            } else {
                               this.$Message.error("添加失败");
                            }
                        },
                        (error)=>{
                            console.log(error);
                        }
                );
            },

        }
    }
</script>
<style scoped>
    .editor-btn{
        margin-top: 20px;
    }
</style>